package site.assad.springi18n;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;
import java.util.Locale;

/**
 * Author: Al-assad 余林颖
 * E-mail: yulinying_1994@outlook.com
 * Date: 2017/12/1 15:23
 * Description: 测试 spring 获取占位符参数化的资源
 */
public class FmtI18nTest {

    public static void main(String[] args){
        //运行该测试时，需要将 site/assad/springi18m/beans.xml 中 id="messageSource"的bean注释掉，原因时在一个spring容器中只能存在一个messageSource bean

        //加载Spring容器
        ApplicationContext ctx = new ClassPathXmlApplicationContext("site/assad/springi18n/beanFmt.xml");
        //设置占位符参数
        Object[] params = {"Al-assad",new Date()};
        //获取资源键值
        String common1 = ctx.getMessage("greeting.common", params,Locale.CHINA);
        String morning1 = ctx.getMessage("greeting.morning", params,Locale.CHINA);
        String afternoon1 = ctx.getMessage("greeting.afternoon", params,Locale.CHINA);
        String common2 = ctx.getMessage("greeting.common", params,Locale.US);
        String morning2 = ctx.getMessage("greeting.morning", params,Locale.US);
        String afternoon2 = ctx.getMessage("greeting.afternoon", params,Locale.US);

        System.out.println(common1+"\n"+morning1+"\n"+afternoon1+"\n"+common2+"\n"+morning2+"\n"+afternoon2);

        /*output：
        *   你好!Al-assad,今天是 17-12-1
            上午好!Al-assad,现在的时间是 下午3:48
            下午好!Al-assad,现在的时间是 下午3:48
            How are you!Al-assad,today is 12/1/17
            Good morning!Al-assad,now is 3:48 PM
            Good afternoon!Al-assad,now is3:48 PM
            */


    }

}
